/**
 * 
 */
var _bucketName = "";
var _path ="";
var _type = "";
var netdisk = {
		listdata : function(path,folderName,pathOperation){
			var url = baseURL;
			switch(_type){
			case "disk":
				url += "/os/netdisk/list";
				break;
			
			case "recycle":
				url += "/os/netdisk/recycle";
				break;
			
			default:
				break;
			}
			$.ajax({
				type : "get",
				url : url,
				data : { bucketName : _bucketName, path : path, folderName : folderName},
				dataType : "html",
				success : function(html) {
					switch(pathOperation){
						case "getNetList":
							if(_path == ""){
								_path = folderName;
							}else{
								_path = _path + "/"+folderName;
							}
							break;
						
						case "getUpList":
							_path = path;
							break;
						
						case "getHomeList":
							_path = "";
							break;

						default:
							break;
					}
					$("#list").empty().html(html);
					$('#location').text(_path);
				}
			});
		},
		list : function(){
			var bucketName = $('#bucketName').val();
			_bucketName = bucketName;
			_type = "disk";
			netdisk.listdata("","","getHomeList");
		},
		
		nextList : function(value){
			var folderName = value;
			var path = _path;
			netdisk.listdata(path,folderName,"getNetList");
		},
		
		up : function(){
			var index = _path.lastIndexOf("/");
			var path =""
			if(index != -1){
				var path = _path.substr(0,index);
			}
			netdisk.listdata(path,"","getUpList");
		},
		
		home : function(){
			netdisk.listdata("","","getHomeList");
		},
		
		createFolder : function(){
			var title = "创建文件夹";
			var param = {};
			common.dialog({
				obj : "#createFolderDialog",
				url : baseURL + "/os/netdisk/createFolder",
				param : param,
				title : title,
				width : 400,
				confirm : function() {
					if($("#createFolderForm").form('validate')==true){
						// Click the "Confirm" button to save user info.
						netdisk.createFolderSave();
					}
					else{
						common.showTip({
							title : localeMsg.common.warn,
							text : localeMsg.common.invalidData
						});
					}
				}//confirm
			});//common.dialog
		},//createFolder
		
		createFolderSave : function(){
			var url = baseURL+"/os/netdisk/saveNewFolder";
			var name = $('#newFolderName').val();
			$.ajax({
				type : "post",
				url : url,
				data : { bucketName : _bucketName, name : name, path : _path},
				dataType : "json",
				success : function(json) {
					if (json.result && json.result == "success") {
						common.showTip({
							success : true,
							title : localeMsg.common.info,
							text : localeMsg.common.saveSuccess,
							callback : function() {
								netdisk.listdata(_path,"","");
							}
						});
					}//if
					else {
						if (json.result && json.result == "failure"){
							common.showTip({
								success : false,
								title : localeMsg.common.warn,
								text : localeMsg.common.saveFailed,
							});
						}
						else{
							common.showTip({
								success : false,
								title : localeMsg.common.warn,
								text : localeMsg.role.neverdelete,
							});
						}
					}//else
				}//success
			});//ajax
		},
		
		disk : function(){
			netdisk.list();
		},
		
		recycleBin : function(){
			var bucketName = $('#recycleBucket').val();
			_bucketName = bucketName;
			_type = "recycle";
			_path = "";
			netdisk.listdata("","","","getHomeList");
		},
		
		shareManage :function(){
			common.showTip({
				title :"待施工",
				text : "待施工"
			});
		},
		
		upLoad : function(){
			window.showModalDialog("1111");
		},
		
		share : function(){
			common.showTip({
				title :"待施工",
				text : "待施工"
			});
		},
		
		download : function(){
			common.showTip({
				title :"待施工",
				text : "待施工"
			});
		},
		
		logicalRemove : function(){
			var object=[];
			$('input[name="object"]:checked').each(function(){
				object.push($(this).val()); 
	            });
			
			$.ajax({
				type : "post",
				url : baseURL + "/os/netdisk/logicalRemove",
				data : {bucketName : _bucketName, path : _path, object : object},
				traditional: true,
				dataType : "json",
				success : function(json) {
					if (json.result && json.result == "success") {
						common.showTip({
							success : true,
							title : localeMsg.common.info,
							text : "成功移入回收站",
							callback : function() {
								netdisk.listdata(_path,"","");
							}
						});
					}
					else {
						if (json.result && json.result == "failure"){
							common.showTip({
								success : false,
								title : localeMsg.common.warn,
								text : localeMsg.common.deleteFailed,
							});
						}
						else{
							common.showTip({
								success : false,
								title : localeMsg.common.warn,
								text : localeMsg.role.neverdelete,
							});
						}
					}
				}
			});
		},
		
		restore : function(){
			var object=[];
			$('input[name="object"]:checked').each(function(){
				object.push($(this).val()); 
	            });
			
			$.ajax({
				type : "post",
				url : baseURL + "/os/netdisk/restore",
				data : {bucketName : _bucketName, path : _path, object : object},
				traditional: true,
				dataType : "json",
				success : function(json) {
					if (json.result && json.result == "success") {
						common.showTip({
							success : true,
							title : localeMsg.common.info,
							text : "恢复成功",
							callback : function() {
								netdisk.listdata(_path,"","");
							}
						});
					}
					else {
						if (json.result && json.result == "failure"){
							common.showTip({
								success : false,
								title : localeMsg.common.warn,
								text : localeMsg.common.deleteFailed,
							});
						}
						else{
							common.showTip({
								success : false,
								title : localeMsg.common.warn,
								text : localeMsg.role.neverdelete,
							});
						}
					}
				}
			});
		},
		
		deleteObject : function(){
			$('input[name="object"]:checked').each(function(){
				object.push($(this).val()); 
	            });			
			$.ajax({
				type : "post",
				url : baseURL + "/os/netdisk/delete",
				data : {bucketName : _bucketName, path : _path, object : object},
				traditional: true,
				dataType : "json",
				success : function(json) {
					if (json.result && json.result == "success") {
						common.showTip({
							success : true,
							title : localeMsg.common.info,
							text : localeMsg.common.deleteSuccess,
							callback : function() {
								netdisk.listdata(_path,"","");
							}
						});
					}
					else {
						if (json.result && json.result == "failure"){
							common.showTip({
								success : false,
								title : localeMsg.common.warn,
								text : localeMsg.common.deleteFailed,
							});
						}
						else{
							common.showTip({
								success : false,
								title : localeMsg.common.warn,
								text : localeMsg.role.neverdelete,
							});
						}
					}
				}
			});
		},
		clear : function(){
			$.ajax({
				type : "post",
				url : baseURL + "/os/netdisk/clear",
				data : {bucketName : _bucketName},
				traditional: true,
				dataType : "json",
				success : function(json) {
					if (json.result && json.result == "success") {
						common.showTip({
							success : true,
							title : localeMsg.common.info,
							text : localeMsg.common.deleteSuccess,
							callback : function() {
								netdisk.listdata(_path,"","");
							}
						});
					}
					else {
						if (json.result && json.result == "failure"){
							common.showTip({
								success : false,
								title : localeMsg.common.warn,
								text : localeMsg.common.deleteFailed,
							});
						}
						else{
							common.showTip({
								success : false,
								title : localeMsg.common.warn,
								text : localeMsg.role.neverdelete,
							});
						}
					}
				}
			});
		},
		
		move : function(){
			common.showTip({
				title :"待施工",
				text : "待施工"
			});
		},
		
		copy : function(){
			common.showTip({
				title :"待施工",
				text : "待施工"
			});
		},
		
		rename : function(){
			common.showTip({
				title :"待施工",
				text : "待施工"
			});
		},
		/**
		 *表单数据验证
		*/
		validate : function(){
		    $('#folderName').validatebox({
		        required: true,
		        validType: ['maxLength[50]'] //TODO 文件名称不能包含 /
		    });
		},
};